package com.example.lx6_1.login

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.example.base.mvvm.BaseActivity
import com.example.lx6_1.databinding.ActivityLoginBinding
import com.example.lx6_1.login.LoginViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LoginActivity : BaseActivity<ActivityLoginBinding,LoginViewModel>() {
    override fun initView() {
        binding.btn.setOnClickListener {
            viewModel.getLogin(binding.etUsername.text.toString(),binding.etPassword.text.toString())
        }
    }

    override fun initData() {
        viewModel.loginData.observe(this){
            ARouter.getInstance().build("/app/MainActivity").navigation()
            ToastUtils.showLong("登录成功")
            SPUtils.getInstance().put("token",it.token)
        }
    }
}